package com.version2_0.dao.implement;

import com.version2_0.dao.SearchDao2_0;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Map;

/**
 * Created by reeveslee on 16/6/16.
 */
@Repository
public class SearchDaoImpl2_0 implements SearchDao2_0 {
    private static final Logger LOGGER = Logger.getLogger(SearchDaoImpl2_0.class);

    @Autowired
    private JdbcTemplate jdbcTemplate;

    @Override
    public List<Map<String, Object>> hotPages() {
        String sql = "SELECT id AS pageId,titleImage,title,source,readNumber FROM v2_pages ORDER BY readNumber DESC LIMIT 10";
        return jdbcTemplate.queryForList(sql);
    }

    @Override
    public List<Map<String, Object>> hotKeys() {
        String sql = "SELECT keyname FROM v2_hotkeys ORDER BY orders DESC";
        return jdbcTemplate.queryForList(sql);
    }

    @Override
    public List<Map<String, Object>> votes(String key) {
        // TODO: 设计图投票需要图片
        String sql = "SELECT id,";
        return null;
    }

    @Override
    public List<Map<String, Object>> videos(String key) {
        String sql = "SELECT id,title,source,readNumber FROM v2_vedios WHERE title LIKE '%" + key + "%'" + "ORDER BY id DESC";
        return jdbcTemplate.queryForList(sql);
    }

    @Override
    public List<Map<String, Object>> pages(String key) {
        String sql = "SELECT id AS pageId,titleImage,title,source,readNumber FROM v2_pages WHERE title LIKE '%" + key + "%'" + " ORDER BY id DESC";
        return jdbcTemplate.queryForList(sql);
    }
}
